<?php
/**
 * @name Bootstrap
 * @author root
 * @desc 所有在Bootstrap类中, 以_init开头的方法, 都会被Yaf调用,
 * @see http://www.php.net/manual/en/class.yaf-bootstrap-abstract.php
 * 这些方法, 都接受一个参数:Yaf_Dispatcher $dispatcher
 * 调用的次序, 和申明的次序相同
 */


class Bootstrap extends Yaf_Bootstrap_Abstract{

    public function _initConfig() {
        //把配置保存起来
        $arrConfig = Yaf_Application::app()->getConfig();
        Yaf_Registry::set('config', $arrConfig);

        //session start
        $session = Yaf_Session::getInstance();
        $session->start();

        Yaf_Registry::set('session',$session);
    }

    public function _initPlugin(Yaf_Dispatcher $dispatcher) {
        //注册Plugin
        $misPlugin = new BasePlugin();
        $dispatcher->registerPlugin($misPlugin);
    }

    public function _initRoute(Yaf_Dispatcher $dispatcher) {
        //在这里注册自己的路由协议,默认使用简单路由
        $router = $dispatcher->getRouter();
        $router->addConfig(Yaf_Registry::get("config")->routes);

        $smatyConfig = Yaf_Registry::get("config")->smarty;
        SmartyAdapter::setConfig($smatyConfig);


    }

    public function _initView(Yaf_Dispatcher $dispatcher){
        //不使用yaf本身的view
        $dispatcher->disableView();
    }

    public function _initRequest(Yaf_Dispatcher $dispatcher)
    {
        $dispatcher->setRequest(new Request());
    }
}
